﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using AppLab.Web;
using AppLab.Data.Models;

namespace AppLab.Controls
{
    public class UploadUpgradePackageTextBox : UploadTextBox
    {
        public UploadUpgradePackageTextBox(SubmitData e)
            : base(e)
        {
            base.TextChanged += new TextChangedEventHandler(UploadUpgradePackageTextBox_TextChanged);
        }

        void UploadUpgradePackageTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (selectedFile != null)
            {
                if (string.IsNullOrEmpty(base.Text.Replace(" ", "")))
                {
                    submitData.UpGradePackageContent = null;
                }
            }
            else
            {
                base.Text = string.Empty;
            }
        }

        public override void UpdateFileContent(System.IO.FileInfo fi)
        {
            if (fi.Length > 4 * 1024 * 1024)
            {
                MessageBox.Show("文件不能大于4M！");
                return;
            }

            using (var s = fi.OpenRead())
            {
                var content = new byte[s.Length];
                s.Read(content, 0, (int)s.Length);
                submitData.UpGradePackageContent = content;
            }
        }
    }
}
